<template>
  <div v-show="isExpand" class="aside">
    <div class="asideHeader">
      <div class="asideHeaderBtn">
        <div
          style="background: #567fff; color: #fff"
          class="btn"
          type="primary"
          @click="showHome"
        >
          创意广场
        </div>
        <div
          style="background: #48a0ff; color: #fff"
          class="btn"
          type="primary"
          @click="showHome"
        >
          Agent中心
        </div>
      </div>
      <div
        style="background: #e5eefd; color: rgb(73, 131, 236)"
        class="asideHeaderBtn2"
        @click="handleCreate"
      >
        <el-icon :size="16" style="padding: 2px 5px 0px 0px"><Plus /></el-icon
        >创建新的对话
      </div>
      <div class="asideHeaderTab">
        <div
          v-for="item in selectType"
          :key="item.value"
          :class="{ active: useDialogueStore.type.value == item.value }"
          @click="typeChange(item)"
        >
          {{ item.label }}
        </div>
      </div>
    </div>
    <div class="history">
      <div class="item-box active">
        <div class="name">新对话窗口</div>
        <div class="bar">
          <div class="time">5分钟之内</div>
          <div class="delete"><Delete /></div>
        </div>
      </div>
      <div class="item-box">
        <div class="name">小红书文案</div>
        <div class="bar">
          <div class="time">2024-01-18 15:23:46</div>
          <div class="delete"><Delete /></div>
        </div>
      </div>
    </div>
    <div class="asideFooter">
      <div class="btn" @click="clearHistoryList">
        <el-icon>
          <Delete />
        </el-icon>
        一键清空
      </div>
      <div class="btn" @click="handleExpandChange">
        <SvgIcon name="clear"></SvgIcon>收起
      </div>
    </div>
  </div>

  <div class="expand" @click="handleExpandChange">
    <div v-if="!isExpand" class="btn">></div>
  </div>
  <div class="adide-page"></div>
</template>
<script setup>
import { computed, ref, watch } from "vue";
import { User, Plus, InfoFilled, Delete } from "@element-plus/icons-vue";
import { useDialogue } from "@/store/dialogue.store";
import EditQuestion from "./EditQuestion.vue";
import Asklibrary from "./Asklibrary.vue";
import Empty from "@/views/components/Empty.vue";
import { ElMessage, ElMessageBox } from "element-plus";
const selectType = [
  {
    value: "history",
    label: "历史对话",
  },
  {
    value: "quick",
    label: "收藏助手",
  },
];

const useDialogueStore = useDialogue();
const emits = defineEmits(["sendMessage", "clear"]);

const showIndex = ref(-1);

const history = ref([]);
watch(
  () => useDialogueStore.historyList,
  (val) => {
    history.value = val;
  },
  { immediate: true }
);

function handleCreate() {
  emits("clear");
}

const typeChange = (val) => {
  useDialogueStore.updateType(val);
};

const showHome = () => {
  useDialogueStore.updateisShowHome(true);
};

const clearHistoryList = () => {
  if (!useDialogueStore.isSendingVaild()) {
    return;
  }
  ElMessageBox.confirm("确定要清空历史记录?清空后不可恢复!", "警告！", {
    confirmButtonText: "删除",
    cancelButtonText: "取消",
    type: "info",
  })
    .then(async () => {
      useDialogueStore.clearHistoryList();
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除",
      });
    });
};

const sendMessage = (item) => {
  emits("sendMessage", item);
};

//#region  侧边栏是否开启
const isExpand = ref(true);
const asideW = computed(() => {
  if (isExpand.value) {
    return "250px";
  }
  return "0px";
});
const handleExpandChange = () => {
  isExpand.value = !isExpand.value;
};
watch(
  () => useDialogueStore.showPdf,
  (val) => {
    isExpand.value = !val;
  },
  { immediate: true }
);
//#endregion
</script>
<style lang="scss">
.aside {
  display: flex;
  flex-direction: column;
  background-color: #fff;
  width: 260px;
  .asideHeader {
    overflow: hidden;
    .asideHeaderBtn,
    .asideFooter {
      padding: 12px;
      display: flex;
      justify-content: space-between;

      .btn {
        display: flex;
        justify-content: center;
        width: 112px;
        height: 36px;
        background: #f5f5f5;
        cursor: pointer;

        border-radius: 4px;
        color: #111;
        line-height: 43px;
        align-items: center;

        &:hover {
          background: #6d63ae;
          color: #fff;
        }
      }
    }

    .asideHeaderBtn2 {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 36px;
      font-size: 14px;
      color: #fff;
      flex: 1;
      margin: 0 12px;
      border-radius: 4px;
      cursor: pointer;
    }

    .asideHeaderTab {
      margin-top: 18px;
      display: flex;
      height: 38px;
      justify-content: space-around;

      div {
        color: #111;
        justify-content: center;
        display: flex;
        text-align: center;
        margin-bottom: 10px;
        cursor: pointer;
      }

      div[class~="active"] {
        color: #2171fe;
        font-weight: 600;
        border-bottom: 2px solid #2171fe;
      }
    }
  }
  .history {
    clear: both;
    overflow: hidden;
    padding-right: 12px;
    padding-left: 12px;
    height: calc(100vh - 257px);
    .item-box {
      background-color: #f8f8f8;
      padding: 12px 15px;
      overflow: hidden;
      margin-bottom: 5px;
      border-radius: 0 4px 4px 0;
      cursor: pointer;
      .name {
        color: #2171fe;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 24px;
      }
      .bar {
        height: 24px;
        display: flex;
        align-items: center;
        margin-top: 4px;
        .time {
          flex: 1;
          width: 1%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          color: #999;
        }
        .delete {
          width: 14px;
          height: 14px;
          color: #999;
          cursor: pointer;
        }
      }
      &.active {
        border-left: solid 3px #2171fe;
      }
    }
  }
  .asideFooter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0px 12px 12px 12px;
    box-sizing: border-box;

    .btn {
      display: flex;
      justify-content: center;
      width: 112px;
      height: 32px;
      background: #e5eefd;
      border-radius: 4px;
      line-height: 32px;
      align-items: center;
      color: #4983ec;
      cursor: pointer;

      &:hover {
        background: #2171fe;
        color: #fff;
      }
    }
  }
}

.expand {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;

  .btn {
    width: 14px;
    display: flex;
    justify-content: center;
    background: #f5f5f5;
    border: 1px solid #413a6e;
    border-radius: 4px;
    color: #111;
    align-items: center;

    &:hover {
      background: #6d63ae;
      color: #fff;
    }
  }
}
</style>
